﻿using System;

namespace Common
{
    // TODO => improve
    public class Phone
    {
        public enum PhoneType
        {
            Regular = 1,
            Mobile = 2
        }

        #region Public Methods

        public static string ApplyFormat(string number, string countryCode = null, string areaCode = null)
        {
            if (number == null)
                return number;

            if (number.Length < 8)
                return number;

            number = RemoveFormat(number);

            return String.Format("{0}-{1}", number.Substring(0, 4), number.Substring(4, 4));
        }

        public static string RemoveFormat(string number)
        {
            if (number == null)
                return number;

            return number.Replace("-", String.Empty);
        }

        public static bool ValidatePhoneNumber(PhoneType phoneType, string phoneNumber)
        {
            if (string.IsNullOrEmpty(phoneNumber))
                return false;

            switch (phoneType)
            {
                case PhoneType.Regular:
                    return true;
                    break;
                case PhoneType.Mobile:
                    return phoneNumber.Length == 12 ? true : false;
                    break;
            }

            return true;
        }
        
        #endregion
    }
}
